package com.zhoushihao.class0814;

import java.util.*;

public class Library {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        for (int i = 0; i < n; i++) {
            int borrowTime = 0;
            double averageTime = 0;
            double totalTime = 0;
            Map<Integer, Integer> borrowMap = new HashMap<>();
            Map<Integer, Integer> returnMap = new HashMap<>();
            while (true) {
                String s = sc.nextLine();
                String[] str = s.split(" ");
                if (str[0].equals("0")) {
                    break;
                } else {
                    String[] tmp = str[2].split(":");
                    int time = Integer.parseInt(tmp[0]) * 60 + Integer.parseInt(tmp[1]);
                    int numBook = Integer.parseInt(str[0]);
                    if (str[1].equals("S")) {
                        borrowMap.put(numBook , time);
                    }
                    if(str[1].equals("E") && borrowMap.containsKey(numBook)){
                        totalTime += time - borrowMap.get(numBook);
                        borrowMap.remove(numBook);
                        borrowTime++;
                    }
                }
            }
            if (borrowTime != 0) {
                averageTime = totalTime / borrowTime;
            }
            System.out.println(borrowTime + " " + Math.round(averageTime));
        }
    }
}
